﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Admin.NET.Database.Migrations.Migrations
{
    public partial class AddProjectWorkload : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Project",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "Id主键"),
                    ProjectId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "Project ID"),
                    ProjectName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "Project Name"),
                    ProjectCategory = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true, comment: "Project Category"),
                    ProjectDescription = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true, comment: "Project Description"),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "Start Date"),
                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "End Date"),
                    Region = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "Region"),
                    Currency = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "Currency"),
                    Budget = table.Column<decimal>(type: "decimal(18,2)", nullable: true, comment: "Budget"),
                    ProjectOwnerId = table.Column<long>(type: "bigint", nullable: true),
                    ProjectRespId = table.Column<long>(type: "bigint", nullable: true),
                    Status = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "Status"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "创建时间"),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "更新时间"),
                    CreatedUserId = table.Column<long>(type: "bigint", nullable: true, comment: "创建者Id"),
                    CreatedUserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "创建者名称"),
                    UpdatedUserId = table.Column<long>(type: "bigint", nullable: true, comment: "修改者Id"),
                    UpdatedUserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "修改者名称"),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, comment: "软删除标记")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Project", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Project_sys_user_ProjectOwnerId",
                        column: x => x.ProjectOwnerId,
                        principalTable: "sys_user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Project_sys_user_ProjectRespId",
                        column: x => x.ProjectRespId,
                        principalTable: "sys_user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "Project");

            migrationBuilder.CreateTable(
                name: "ProjectWorkload",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "Id主键"),
                    ProjectId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "Project ID"),
                    WorkloadId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "Workload ID"),
                    AssigneeId = table.Column<long>(type: "bigint", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true, comment: "Description"),
                    Month = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "Month"),
                    Workload = table.Column<decimal>(type: "decimal(18,2)", nullable: true, comment: "Workload Hour"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "创建时间"),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "更新时间"),
                    CreatedUserId = table.Column<long>(type: "bigint", nullable: true, comment: "创建者Id"),
                    CreatedUserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "创建者名称"),
                    UpdatedUserId = table.Column<long>(type: "bigint", nullable: true, comment: "修改者Id"),
                    UpdatedUserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "修改者名称"),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, comment: "软删除标记")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProjectWorkload", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProjectWorkload_sys_user_AssigneeId",
                        column: x => x.AssigneeId,
                        principalTable: "sys_user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "ProjectWorkload");

            migrationBuilder.CreateIndex(
                name: "IX_Project_ProjectOwnerId",
                table: "Project",
                column: "ProjectOwnerId");

            migrationBuilder.CreateIndex(
                name: "IX_Project_ProjectRespId",
                table: "Project",
                column: "ProjectRespId");

            migrationBuilder.CreateIndex(
                name: "IX_ProjectWorkload_AssigneeId",
                table: "ProjectWorkload",
                column: "AssigneeId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Project");

            migrationBuilder.DropTable(
                name: "ProjectWorkload");
        }
    }
}
